﻿using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_SpecialityKinds_Option : BaseForm
    {
        string SpecialityKindsID = string.Empty;
        ServiceBase service = new ServiceBase();
        TB_Sys_SpecialityKinds model = null;
        public Base_SpecialityKinds_Option(string strSpecialityKindsID)
        {
            InitializeComponent();
            SpecialityKindsID = strSpecialityKindsID;
            this.cmbSexType.Properties.NullText = "";
            this.cmbSexType.Properties.Columns.Add(new LookUpColumnInfo("Key", 30, "类型代码"));
            this.cmbSexType.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "类型名称"));
            this.cmbSexType.Properties.DataSource = ConstAppConfig.DicLimitSexType.ToList();
            this.cmbSexType.Properties.DisplayMember = "Value";
            this.cmbSexType.Properties.ValueMember = "Key";           

            if (SpecialityKindsID.ToSafeString().Length > 0)
            {
                model = service.GetSpecialityKindsModel(SpecialityKindsID);
                if (model != null)
                {
                    model.Attach();
                    txt_SpecialityKindsNO.Text = model.SpecialityKindsNO;
                    txt_SpecialityKindsName.Text = model.SpecialityKindsName;
                    txt_SpecialityKindsID.Text = model.SpecialityKindsID;
                    txt_Sort.Text = model.Sort.ToString();
                    cmbSexType.EditValue = model.LimitSex;

                    if (model.IsActive == "1")
                    {
                        chkSFYX.Checked = true;
                    }
                    else
                    {
                        chkSFYX.Checked = false;
                    }

                    if (model.IsSchool == "1")
                    {
                        chkSFXK.Checked = true;
                    }
                    else
                    {
                        chkSFXK.Checked = false;
                    }
                    txt_Fee_First.Text = model.Fee_First.ToString();
                    txt_Fee_Second.Text = model.Fee_Second.ToString();
                    txt_Fee_Third.Text = model.Fee_Third.ToString();
                    txt_Fee_Fourth.Text = model.Fee_Fourth.ToString();
                    txt_Fee_Fifth.Text = model.Fee_Fifth.ToString();
                    txt_Fee_Sixth.Text = model.Fee_Sixth.ToString();
                    txtCounterFee_First.Text = model.CounterFee_First.ToString();
                    txtCounterFee_Second.Text = model.CounterFee_Second.ToString();
                    txtCounterFee_Third.Text = model.CounterFee_Third.ToString();
                    txtCounterFee_Fourth.Text = model.CounterFee_Fourth.ToString();
                    txtCounterFee_Fifth.Text = model.CounterFee_Fifth.ToString();
                    txtCounterFee_Sixth.Text = model.CounterFee_Sixth.ToString();
                }
            }

        }

        private void buttonX2_Click(object sender, EventArgs e)
        {                   
            if (txt_SpecialityKindsNO.Text.ToSafeString().Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请输入专业编码！");
                return;
            }
            if (txt_SpecialityKindsName.Text.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请输入专业名称！");
                return;
            }
            if (txt_SpecialityKindsID.Text.ToSafeString().Length==0)
            {
                DevHelper.ShowErrorMessageBox("请输入专业代码！");
                return;
            }
            if (model == null)
            {
                model = new TB_Sys_SpecialityKinds();
            }
            model.SpecialityKindsNO = txt_SpecialityKindsNO.Text;
            model.SpecialityKindsID = txt_SpecialityKindsID.Text;
            model.SpecialityKindsName = txt_SpecialityKindsName.Text;
            model.Sort = txt_Sort.Text.ToSafeInt();
            model.Fee_First = txt_Fee_First.Text.ToSafeDecimal();
            model.Fee_Second = txt_Fee_Second.Text.ToSafeDecimal();
            model.Fee_Third = txt_Fee_Third.Text.ToSafeDecimal();
            model.Fee_Fourth = txt_Fee_Fourth.Text.ToSafeDecimal();
            model.Fee_Fifth = txt_Fee_Fifth.Text.ToSafeDecimal();
            model.Fee_Sixth = txt_Fee_Sixth.Text.ToSafeDecimal();
            model.CounterFee_First = txtCounterFee_First.Text.ToSafeDecimal();
            model.CounterFee_Second = txtCounterFee_Second.Text.ToSafeDecimal();
            model.CounterFee_Third = txtCounterFee_Third.Text.ToSafeDecimal();
            model.CounterFee_Fourth = txtCounterFee_Fourth.Text.ToSafeDecimal();
            model.CounterFee_Fifth = txtCounterFee_Fifth.Text.ToSafeDecimal();
            model.CounterFee_Sixth = txtCounterFee_Sixth.Text.ToSafeDecimal();
            model.ExamYear = SessionerHelper.SystemYear;
            if (this.cmbSexType.Text == "")
            {
                model.LimitSex = "0";
            }
            else
            {
                model.LimitSex = cmbSexType.EditValue.ToSafeString();
            }
            if (chkSFXK.Checked)
            {
                model.IsSchool = "1";
            }
            else
            {
                model.IsSchool = "0";
            }
            if (chkSFYX.Checked)
            {
                model.IsActive = "1";
            }
            else
            {
                model.IsActive = "0";
            }

            if (service.SaveSpecialityKinds(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
